package codeTop;

public class q169 {
    public int majorityElement(int[] nums) {
        int temp = nums[0];
        int cnt = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == temp) {
                cnt++;
            }else {
                if (--cnt == 0) {
                    temp = nums[i];
                    cnt = 1;
                }
            }
        }
        return temp;
    }
}
